package Servlet.Blog.dao.impl;

import Servlet.Blog.dao.UserDao;
import Servlet.Blog.entity.User;
import Servlet.Blog.util.DBUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liyy
 * @description
 * @time 2020/10/12 11:42
 */
public class UserDaoImpl implements UserDao {

    //private static final Logger logger = Logger.getLogger(UserDaoImpl.class); //默认log4j对象
    //private static final Logger logger1=Logger.getLogger("batch1");//batch1 log4j对象
    //private static final Logger logger2=Logger.getLogger("batch2"); //batch2 log4j对象


    @Override
    public List<User> queryUserList() {
        List<User> userList = new ArrayList<>();
        Connection conn = DBUtil.getConnection();
        String sql = "select * from blogusers";
        try{
            PreparedStatement pstmt = conn.prepareStatement(sql);
            ResultSet rst = pstmt.executeQuery();
            while(rst.next()){
                User user = new User();
                user.setId(rst.getInt("id"));
                user.setUsername(rst.getString("username"));
                user.setUserpass(rst.getString("userpass"));
                user.setCreationtime(rst.getLong("creationtime")+"");
                user.setStatus(rst.getByte("status"));
                userList.add(user);
            }
        }catch (Exception e){
            //logger.error("queryUserList error",e);
            System.out.println(e.getMessage());
        }

        return userList;
    }

    @Override
    public int addUser(User BlogUser) {
        return 0;
    }

    @Override
    public int delUserById(Integer id) {
        return 0;
    }

    @Override
    public int updateUser(User user) {
        return 0;
    }

    @Override
    public User getUserById(Integer id) {
        return null;
    }
}
